<?php
/**
 * trendscontroller.php
 * 
 * Create on 2015-04-02
 * Create by yuebin
 */
namespace haibao\cms\business\control\pc\index;

use haibao\cms\business\control\PublicController as PublicControllerBusiness;
use haibao\cms\business\control\pc\entity\ArticleEntity;
class TrendsController extends IndexController{
	
	const TRENDS_TAG = 310;
	const TRENDS_BLOG_CATEGORY = 93;
	public function __construct($updateTime = null,$controlId,$isPublish){
		$this->conditionTagId = self::TRENDS_TAG;
		parent::__construct($updateTime,$controlId,$isPublish);
	}
	
	/**
	 * 显示模版内容（模版动态数据的绑定和模版输出）
	 * @param : String $content
	 * @param : Array $controlData;
	 */
	public function displayTemplateHtml(){

		$controlData = $this->getParameter(self::$CONTROL_DATA);
		$content = $this->getParameter(self::$CONTROL_CONTENT);
		
		if($controlData['manual']){
			// 第一屏
			$this->getFirstActualData($controlData['manual']);
		}
		// 处理keywords
		$this->assign('tagInfo', PublicControllerBusiness::getKeyWordsByChannel($this->conditionTagId));

		$this->assign('wordLinkList',$this->getWordLinkList($controlData['auto'],self::getTagChannel($this->conditionTagId)));
		
		$this->assign('attentionType',\haibao\www\model\data\Favorite::ATTENTION_TYPE_BLOGGER);
		$this->assign('moreUrl', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_BOZHU).'/cate/'.self::TRENDS_BLOG_CATEGORY.'/0/');
		$this->assign('channelUrl', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_FASHION));
		$path = $this->generateHtmlPath(__CLASS__);
		$isNewHtml = $this->generateHtml($path,$content);

		$content = $this->getHtml($path);
		$content = $this->replaceCDNLink($content);
		return $content;
	}
	
	/**
	 * 获取时装文章第一屏数据
	 * 获取时装下的所有标签
	 * 根据所有的标签取出最新的5篇文章和对应的标签（做为keywords）
	 * @param : $dataCondition 数据条件
	 */
	public function getFirstActualData($dataCondition){

		$articleEntity = new ArticleEntity();
		$articleEntity->setLevel($dataCondition['level']);
		$articleEntity->setBigLevel($dataCondition['biglevel']);
		$articleEntity->setLimit($dataCondition['limit']);
		$articleEntity->setIsProImage(true);
		$articleEntity->setIsLeftJoinTag(true);
		$articleEntity->setIsPrimaryTag(false);
		$articleEntity->setIsConditionTag(true);
		$articleEntity->setIsReturnTag(true);
		$articleEntity->setIsImageColl(true);
		$articleEntity->setSource(__CLASS__);
		$articleEntity->setTagIds($this->conditionTagId);
		$articleEntity->setIsDebug(false);
		$articleEntity->setIsOnlyReturnPrimaryTag(true);
		$articleEntity->setProImageLevel(array(\haibao\cms\model\data\ArticleProImage::Level_FIVE,\haibao\cms\model\data\ArticleProImage::Level_SEVEN));
		
		$this->articleAction->setArticleEnity($articleEntity);
		list($articles,$imageColls) = $this->articleAction->getListForNew();
		
		$mergeData = $this->mergeData($articles['list'],$imageColls['list'],$articleEntity->getLimit());
		list($firstLeftArticle,$firstRightArticle) = $this->packageMergeData(self::PACKAGE_DATA_TYPE_INDEX_TREND_OR_STAR, $mergeData, $articles, $imageColls);
		$this->assign('firstLeftArticle',json_decode(json_encode(array_values($firstLeftArticle))));
		$this->assign('firstRightArticle', json_decode(json_encode(array_values($firstRightArticle))));
	}
}